<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>开发部项目管理登录</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .login-container {
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            width: 400px;
            border: 2px solid #4a90e2;
        }

        .login-title {
            text-align: center;
            color: #4a90e2;
            font-size: 24px;
            margin-bottom: 30px;
            font-weight: bold;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
        }

        .form-group input[type="text"],
        .form-group input[type="password"] {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            transition: border-color 0.3s;
        }

        .form-group input:focus {
            outline: none;
            border-color: #4a90e2;
        }

        .form-group input.error {
            border-color: #e74c3c;
        }

        .login-btn {
            width: 100%;
            padding: 12px;
            background: #4a90e2;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .login-btn:hover {
            background: #357abd;
        }

        .remember-me {
            display: flex;
            align-items: center;
            margin-top: 15px;
        }

        .remember-me input[type="checkbox"] {
            margin-right: 8px;
            width: 16px;
            height: 16px;
        }

        .remember-me label {
            color: #666;
            font-size: 14px;
        }

        .error-message {
            color: #e74c3c;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }

        .success-message {
            color: #27ae60;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h1 class="login-title">开发部项目管理登录</h1>
        
        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" placeholder="请输入用户名">
                <div class="error-message" id="username-error"></div>
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" placeholder="请输入密码">
                <div class="error-message" id="password-error"></div>
            </div>
            
            <button type="submit" class="login-btn">登录</button>
            
            <div class="remember-me">
                <input type="checkbox" id="remember" name="remember">
                <label for="remember">下次登录是否记住密码？</label>
            </div>
        </form>
        
        <div class="success-message" id="success-message"></div>
    </div>

    <script>
        // 模拟用户数据
        const users = [
            { username: 'zhangsan', password: '123456', role: 'member', name: '张三' },
            { username: 'lisi', password: '123456', role: 'member', name: '李四' },
            { username: 'wangwu', password: '123456', role: 'member', name: '王五' },
            { username: 'minister', password: '123456', role: 'minister', name: '部长' }
        ];

        // 检查是否有保存的登录信息
        window.onload = function() {
            const savedUsername = localStorage.getItem('savedUsername');
            const savedPassword = localStorage.getItem('savedPassword');
            
            if (savedUsername && savedPassword) {
                document.getElementById('username').value = savedUsername;
                document.getElementById('password').value = savedPassword;
                document.getElementById('remember').checked = true;
            }
        };

        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const username = document.getElementById('username').value.trim();
            const password = document.getElementById('password').value.trim();
            const remember = document.getElementById('remember').checked;
            
            // 清除之前的错误提示
            clearErrors();
            
            // 验证输入
            if (!username) {
                showError('username', '用户名不能为空');
                return;
            }
            
            if (!password) {
                showError('password', '密码不能为空');
                return;
            }
            
            // 验证用户
            const user = users.find(u => u.username === username && u.password === password);
            
            if (user) {
                // 保存登录信息
                if (remember) {
                    localStorage.setItem('savedUsername', username);
                    localStorage.setItem('savedPassword', password);
                } else {
                    localStorage.removeItem('savedUsername');
                    localStorage.removeItem('savedPassword');
                }
                
                // 保存用户信息到sessionStorage
                sessionStorage.setItem('currentUser', JSON.stringify(user));
                
                showSuccess('登录成功，正在跳转...');
                
                // 跳转到项目总览页面
                setTimeout(() => {
                    window.location.href = 'project-overview.html';
                }, 1000);
            } else {
                showError('password', '用户名或密码错误，请重新输入');
            }
        });

        function showError(fieldId, message) {
            const field = document.getElementById(fieldId);
            const errorDiv = document.getElementById(fieldId + '-error');
            
            field.classList.add('error');
            errorDiv.textContent = message;
            errorDiv.style.display = 'block';
        }

        function clearErrors() {
            const errorDivs = document.querySelectorAll('.error-message');
            const inputs = document.querySelectorAll('input');
            
            errorDivs.forEach(div => {
                div.style.display = 'none';
            });
            
            inputs.forEach(input => {
                input.classList.remove('error');
            });
        }

        function showSuccess(message) {
            const successDiv = document.getElementById('success-message');
            successDiv.textContent = message;
            successDiv.style.display = 'block';
        }
    </script>
</body>
</html>


